const { TeamOrder } = require("../../config/play_def");

cc.Class({
    extends: cc.Component,

    properties: {
        model: sp.Skeleton
    },
    initPage(){},
    updatePage(param){
        gg.data.pause = true
        this.swap_in_list = param.swap_in_list
        this.swap_list = param.swap_list
        this.model.defaultSkin = param.debut
        this.model.setSkin(param.debut)
        this.model.setAnimation(0,`debut`,false)
        this.model.setCompleteListener((trackEntry) => {
            var animationName = trackEntry.animation ? trackEntry.animation.name : "";
            this.listenAniTag(animationName)
        });
    },
    closeUI(){
        gg.data.pause = false

        if(this.swap_list.length && this.swap_in_list.length){
            let in_list = this.swap_in_list[0].split("/")
            if(in_list[1] == "1015"){
                let center_index = TeamOrder.indexOf(1)
                gg.control.roleScript[center_index + 1].swapIn(this.swap_in_list[0])
            }else{
                for(let i = 0;i < this.swap_list.length; i++){
                    for(let key in gg.control.roleScript){
                        let role_script = gg.control.roleScript[key]
                        if(role_script.role_id == parseInt(this.swap_list[i])){
                            if(this.swap_in_list[i]){
                                role_script.swapIn(this.swap_in_list[i])                       // 换入
                            }
                        }
                    }
                }
            }
        }
        this.model.setCompleteListener(null)
    },
    listenAniTag(ani){
        switch(ani){
            default:
                this.uiBase.closePage()
            break
        }
    },
});
